<template>
  <div id="chart" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
import resize from '../../components/Charts/mixins/resize'
import loadApi from '@/api/img';
export default {
  name: 'funnelChart',
  mixins: [resize],
  props: {
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '1000%'
    }
  },
  data(){
    return {

    }
  },
  mounted() {
    this.setChart()
  },
  methods: {
    async setChart() {
      // 基于准备好的dom，初始化echarts实例
      this.chart = echarts.init(document.getElementById('chart'))
      var data1 = []
      var data2 = [
        {
          value:'',
          name:''
        },
      ]
      let res = await loadApi.listAll()
      for (var i = 0; i < res.data.length; i++) {
        data2.push({value: '',name: ''})
        data1.push(res.data[i].entryname + res.data[i].projectname)
        data2[i].value = res.data[i].quantities
        data2[i].name = res.data[i].entryname+res.data[i].projectname
        console.log(data1.length)
      }

      // 指定图表的配置项和数据
      var option = {
        title: {
          text: '漏斗图'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c}%'
        },
        toolbox: {
          feature: {
            dataView: { readOnly: true },
            restore: {},
            saveAsImage: {}
          }
        },
        legend: {
          data: data1
        },
        series: [
          {
            name: 'Funnel',
            type: 'funnel',
            left: '10%',
            top: 60,
            bottom: 60,
            width: '80%',
            min: 0,
            max: 100,
            minSize: '0%',
            maxSize: '100%',
            sort: 'descending',
            gap: 2,
            label: {
              show: true,
              position: 'inside'
            },
            labelLine: {
              length: 10,
              lineStyle: {
                width: 1,
                type: 'solid'
              }
            },
            itemStyle: {
              borderColor: '#fff',
              borderWidth: 1
            },
            emphasis: {
              label: {
                fontSize: 20
              }
            },
            data: data2
          }
        ]
      };
      this.chart.setOption(option)
    }
  }
}
</script>

<style scoped>

</style>
